package com.yloveg.common;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import com.google.gson.Gson;

public class WlUtil {

    public static Map<String, Object> getWl(String no,String type) {
	    String host = "https://kdwlcxf.market.alicloudapi.com";
	    String path = "/kdwlcx";
	    String method = "GET";
	    String appcode = "df7487d9219d49eaaede45d8097389c9";
	    Map<String, String> headers = new HashMap<String, String>();
	    //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
	    headers.put("Authorization", "APPCODE " + appcode);
	    Map<String, String> querys = new HashMap<String, String>();
	    querys.put("no", no);
	    querys.put("type", type);
             //JDK 1.8示例代码请在这里下载：  http://code.fegine.com/Tools.zip
        Map<String, Object> map = new HashMap<String, Object>();
	    try {
	    	/**
	    	* 重要提示如下:
	    	* HttpUtils请从
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
	    	* 下载
	    	*
	    	* 相应的依赖请参照
	    	* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
	    	*/
	    	HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
	    	//System.out.println(response.toString());如不输出json, 请打开这行代码，打印调试头部状态码。
                //状态码: 200 正常；400 URL无效；401 appCode错误； 403 次数用完； 500 API网管错误
	    	//获取response的body
	    	String result = EntityUtils.toString(response.getEntity());
	    	Gson gson = new Gson();
	    	map = gson.fromJson(result, map.getClass());
	    } catch (Exception e) {
	    	e.printStackTrace();
	    }
	    return map;
	}	
}
